const app = getApp()
let topList = [],
page=1,
setList = [];
Page({
 data: {
  DataList:[],
  mode: 1,
  hasReachBottom: "lower",
  tabPosition: ''
 },


 onLoad() {
  this.getUserList()
 },

 async getUserList() {
  let {
   result
  } = await wx.cloud.callFunction({
   name: "getOperateWordList",
   data: {
    type: "topList"
   }
  })
  topList = result.list
  this.setData({
   DataList: topList
  })

  new Promise(()=>{ // 获取上传成功的数据
    topList.forEach(itm => {
      // console.log('itm.status',itm.status)
      let user = itm._id.user
      var countedNames = itm.status.reduce((obj, name) => {
        if (name in obj) {
          obj[name]++
        } else {
          obj[name] = 1
        }
        return obj
      }, {})
      countedNames = countedNames.success || 0
      setList.push({
        countedNames,
        user
      })
    });
    setList.sort((a,b)=>{
        return b.countedNames - a.countedNames
    })
    console.log('setList', setList)
  })
  this.setData({
    mvpUser:setList[0].user,
    mvpAudioCnt:setList[0].countedNames
  })
  console.log('topList',topList)
 },

 // lower: function () {
 //  console.log('上拉了')
 //  let that = this;
 //  // 显示加载图标  
 //  wx.showLoading({
 //   title: '玩命加载中',
 //  })
 //  that.appendRankList();
 // },

 reachBottom: function () {
  wx.showToast({
   title: '已经到底部啦',
   icon: 'none',
   duration: 1000
  })
 },

 moveTabR: function () {
  let that = this;
  console.log("向左")
  page = 1;
  that.setData({
   tabPosition: 'transformR',
   mode: 1,
   DataList:topList
  })
 },
 moveTabL: function () {
  console.log("向右")
  this.setData({
    mode: 2,
    abPosition: 'transformL',
    tabPosition: 'transformL',
    DataList:setList
  })
  
 },

 onUnload(){
    setList=[]
 }
})